<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <style>
    
    
    </style>
  <div class="easyui-panel" style="padding:10px 10px">
  	<div>
  		<form id="taskForm" method="post">
	    	<fieldset style="margin-top:10px;">
    			<legend>基础选项</legend>
    			<table cellpadding="5">
		    		<tr id="symbolTr">
		    			<td style="width:90px;text-align:right">主流币种：</td>
		    			<td style="width:500px;">
		    					<input class="easyui-radiobutton" name="symbol" value="btcusdt" label="btcusdt" labelPosition="after" >
			    				<input class="easyui-radiobutton" name="symbol" value="ethusdt" label="ethusdt" labelPosition="after">
			    				<input class="easyui-radiobutton" name="symbol" value="xrpusdt" label="xrpusdt" labelPosition="after">
			    				<input class="easyui-radiobutton" id="otherSymbol" name="symbol" value="other" label="自定义" labelPosition="after" checked >
		    			</td>
		    		</tr>
		    		<tr>
		    			<td style="width:90px;text-align:right">选择币种：</td>
		    			<td style="width:500px;">
		    				<select id="symbol" class="easyui-combogrid" name="symbolValue" style="width:110px;"
							    data-options="panelWidth:400,
							  					mode: 'remote', 
									    		idField:'symbol',    
									    		textField:'symbol',    
									    		url:'common/getLocalSymbolsByParam',    
										    	columns:[[
										    			{field:'symbol',title:'币种',width:90},    
												        {field:'quoteCurrency',title:'计价币种',width:100},    
												        {field:'pricePrecision',title:'价格精度',width:120},    
												        {field:'amountPrecision',title:'数量精度',width:100} ]]"></select>
		    			</td>
		    		</tr>
	    		</table>
  				</fieldset>
  				<fieldset style="margin-top:10px;">
    				<legend>买入选项</legend>
    					<table cellpadding="5">
    					<tr>
			    			<td style="width:90px;text-align:right">首单金额:</td>
			    			<td colspan="2">
			    				<input class="easyui-numberbox" name="firstMoney" prompt="首单金额" data-options="required:true,min:1,max:9999," iconWidth="28" style="width:80%;height:34px;padding:10px;">
			    			</td>
			    		</tr>
			    		<tr>
			    			<td style="width:90px;text-align:right">买入单数:</td>
			    			<td colspan="2">
			    				<input class="easyui-numberspinner" name="buyTradeLimit" prompt="买入单数上限" value="5" data-options="min:1,max:10,required:true,increment:1,editable:false" style="width:80%;">
			    			</td>
			    		</tr>
			    		<tr>
			    			<td style="width:90px;text-align:right">档位:</td>
			    			<td colspan="2">
			    				<input class="easyui-numberspinner" name="buyLevel" prompt="档位" value="3" data-options="min:1,max:5,required:true,increment:1,editable:false" style="width:80%;"/>
			    			</td >
			    			
			    		</tr>
			    		<tr>
			    			<td style="width:90px;text-align:right">反弹百分比:</td>
			    			<td>
			    				<input class="easyui-numberbox" name="reboundPercent" prompt="反弹百分比" value="0.0"  data-options="required:true,min:0,max:10,precision:1,suffix:'%'"  style="width:120px;">
			    			</td>
			    			<td>
			    				<span style="color:#333;font-size:12px;">注：从最低拐点反弹一定百分比后买入，如果为0%，则达到买入位置立即买入</span>
			    			</td>
			    		</tr>
			    		<tr>
			    			<td style="width:90px;text-align:right">买入策略:</td>
			    			<td colspan="2">
			    				<input class="easyui-radiobutton" name="buyMethod" value="1" label="斐波型" labelPosition="after" checked/>
			    				<input class="easyui-radiobutton" name="buyMethod" value="2" label="倍投" labelPosition="after"/>
			    				<input class="easyui-radiobutton" name="buyMethod" value="3" label="立方倍投" labelPosition="after"/>
			    			</td>
			    		</tr>
	    			</table>
  				</fieldset>
  				<fieldset style="margin-top:10px;">
    				<legend>卖出选项</legend>
    				<table cellpadding="5">
			    		<tr>
			    			<td style="width:90px;text-align:right">止盈百分比:</td>
			    			<td colspan="2">
			    				<input class="easyui-numberbox" name="profitPercent" prompt="止盈百分比" value="2.5"  data-options="required:true,min:1,max:10,precision:1,suffix:'%'"  style="width:80%;">
			    			</td>
			    		</tr>
			    		<tr>
			    			<td style="width:90px;text-align:right">回落百分比:</td>
			    			<td>
			    				<input class="easyui-numberbox" name="fallBackPercent" prompt="回落百分比" value="0.0"  data-options="required:true,min:0,max:10,precision:1,suffix:'%'"  style="width:120px;">
			    			</td>
			    			<td>
			    				<span style="color:#333;font-size:12px;">注：从最高拐点回落一定百分比后卖出，如果为0%，则达到止盈百分比立即卖出</span>
			    			</td>
			    		</tr>
	    			</table>
  				</fieldset>
	</div>
	    </form>
	</div>
  </div>
	
<script type="text/javascript">

$(function(){
	
	  //重写InputMask-currency
    Inputmask.extendAliases({
    	   'money':{
    	      'alias':"currency",
    	      'prefix':""
    	   }
    })
    
	  
	 $("input[name='firstMoney']").next().children("input").inputmask({alias: "money",'rightAlign': false})
	  
	 $('#symbol').combo({  
		 	mode: 'remote', 
		    idField:'symbol',    
		    textField:'symbol',    
		    url:'common/getLocalSymbolsByParam',    
		    columns:[[    
		        {field:'symbol',title:'币种',width:60},    
		        {field:'baseCurrency',title:'计价币种',width:100},    
		        {field:'pricePrecision',title:'价格精度',width:120},    
		        {field:'amountPrecision',title:'数量精度',width:100}    
		    ]]    
		});
	 
	 
	 getTaskById()
	
})




function getTaskById(){
	var id = $('#window_taskEdit').data("id");
	if(id){
		$.messager.progress();
		$.getJSON("../task/getTaskById",{"id":id},function(res){
			$.messager.progress('close');
			if(res.status == 200){
				var obj = res.data;
				$("#symbolTr").css("display","none");
				$('#symbol').combogrid('setValue', obj.symbol);
				
				$('#taskForm').form('load', { // 调用load方法把所选中的数据load到表单中,非常方便
			        firstMoney : obj.firstMoney,
			        buyTradeLimit : obj.buyTradeLimit,
			        buyLevel : obj.buyLevel,
			        reboundPercent : obj.reboundPercent,
			        buyMethod : obj.buyMethod,
			        profitPercent : obj.profitPercent,
			        fallBackPercent : obj.fallBackPercent
			        
			        
			    });
				
				$('#symbol').combogrid('disable');
				
			}else{
				 $.messager.alert('提示',res.message,'info');
				$("#window_taskEdit").window('close');
			}
		})
	}

}

function taskAdd_submitform(_callback){
	$('#taskForm').form('submit',{
		url:"../task/save",
		onSubmit:function(){
			$.messager.progress();
			var isValid =  $(this).form('enableValidation').form('validate');
			if(!isValid){
				$.messager.progress('close');	// 如果表单是无效的则隐藏进度条
			}
			return isValid;
		},
		success: function(res){
			$.messager.progress('close');
			res = JSON.parse(res);
	         if(res.status == 200){
	        	 $.messager.alert('提示',"任务创建成功！",'info',function(){
		        	 _callback();
		        	 
	        	 });
	         }else{
	        	 $.messager.alert('提示',res.message,'info');
	         }
	    } 
	});
}

function taskUpdate_submitform(_callback){
	var id = $('#window_taskEdit').data("id")
	$('#taskForm').form('submit',{
		url:"../task/updateTaskById",
		queryParams:{"id":id},
		onSubmit:function(){
			$.messager.progress();
			var isValid =  $(this).form('enableValidation').form('validate');
			if(!isValid){
				$.messager.progress('close');	// 如果表单是无效的则隐藏进度条
			}
			return isValid;
		},
		success: function(res){
			$.messager.progress('close');
			res = JSON.parse(res);
	         if(res.status == 200){
	        	 $.messager.alert('提示',"任务修改成功！",'info',function(){
	        	/* 	 $("#symbolTr").css("display","block");
	        		 $('#taskForm').form('load', { // 调用load方法把所选中的数据load到表单中,非常方便
	 			        firstMoney : '',
	 			        buyTradeLimit : '5',
	 			        buyLevel : '3',
	 			        reboundPercent : '0.0',
	 			        buyMethod : '1',
	 			        profitPercent : '2.5',
	 			        fallBackPercent : '0.0'
	 			        
	 			        
	 			    }); */
		        	  _callback();
	        	 });
	         }else{
	        	 $.messager.alert('提示',res.message,'info');
	         }
	    } 
	});
}
</script>
